﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Item.cs" company="SMART business">
//   Copyright (c) 2014 All Rights Reserved
// </copyright>
// <summary>
//   The item.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace ComparisonTool
{
    using System;
    using System.Collections.Generic;

    /// <summary>
    /// The item.
    /// </summary>
    public class Item : IComparable
    {
        /// <summary>
        /// The comparing type.
        /// </summary>
        public readonly int ComparingType;

        /// <summary>
        /// Initializes a new instance of the <see cref="Item"/> class.
        /// </summary>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="value">
        /// The value.
        /// </param>
        public Item(string name, string value)
        {
            this.Name = name;
            this.Value = value;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Item"/> class.
        /// </summary>
        /// <param name="comparingType">
        /// The comparing type.
        /// </param>
        /// <param name="items">
        /// The list view item.
        /// </param>
        public Item(int comparingType, List<object> items)
        {
            this.ComparingType = comparingType;
            this.Items = items;
        }

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the value.
        /// </summary>
        public string Value { get; set; }

        /// <summary>
        /// Gets or sets the items.
        /// </summary>
        public List<object> Items { get; set; }

        /// <summary>
        /// The to string.
        /// </summary>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public override string ToString()
        {
            return this.Name;
        }

        /// <summary>
        /// The compare to.
        /// </summary>
        /// <param name="other">
        /// The other.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        public int CompareTo(object other)
        {
            var item = other as Item;

            return item != null ? string.CompareOrdinal(this.Name, item.Name) : 0;
        }
    }
}
